const is_array = require("is-array")
Page({
  data: {
    value: '',
    showClearBtn: false,
    isWaring: false,

    currentValue: '',
    isCurrentWaring: false,
    buttons: [{ text: '取消' }, { text: '确认' }],
    msg: "我是谁",
    radioItems: [
      { name: 'cell standard', value: '0', checked: true },
      { name: 'cell standard', value: '1' }
    ],
    checkboxItems: [
      { name: 'standard is dealt for u.', value: '0', checked: true },
      { name: 'standard is dealicient for u.', value: '1' }
    ],
  },
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value);

    var radioItems = this.data.radioItems;
    for (var i = 0, len = radioItems.length; i < len; ++i) {
      radioItems[i].checked = radioItems[i].value == e.detail.value;
    }

    this.setData({
      radioItems: radioItems,
      [`formData.radio`]: e.detail.value
    });
  },
  checkboxChange: function (e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value);

    var checkboxItems = this.data.checkboxItems, values = e.detail.value;
    for (var i = 0, lenI = checkboxItems.length; i < lenI; ++i) {
      checkboxItems[i].checked = false;

      for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
        if (checkboxItems[i].value == values[j]) {
          checkboxItems[i].checked = true;
          break;
        }
      }
    }

    this.setData({
      checkboxItems: checkboxItems,
      [`formData.checkbox`]: e.detail.value
    });
  },
  tapDialogButton(e) {
    console.log("e=", e.detail)
    this.setData({
      msg: e.detail.item.text
    });
    let b = [12, 34]
    let a = is_array(e)
    console.log(a)
  },  onCurrentInput() {
    this.setData({
      isCurrentWaring: true,
    });
  },
  onInput(evt) {
    const { value } = evt.detail;
    this.setData({
      value,
      showClearBtn: !!value.length,
      isWaring: false,
    });
  },
  onClear() {
    this.setData({
      value: '',
      showClearBtn: false,
      isWaring: false,
    });
  },
  onConfirm() {
    if (this.data.value.length < 16) {
      this.setData({
        isWaring: true,
      });
    }
  },
})
